package com.ogms.dge.container.modules.data.controller;

import com.ogms.dge.container.common.utils.PageUtils;
import com.ogms.dge.container.common.utils.R;
import com.ogms.dge.container.modules.data.converter.RecordConverter;
import com.ogms.dge.container.modules.data.entity.RecordEntity;
import com.ogms.dge.container.modules.data.service.RecordService;
import com.ogms.dge.container.modules.data.service.ServiceService;
import com.ogms.dge.container.modules.method.controller.AbstractController;
import com.ogms.dge.container.modules.sys.service.SysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;



/**
 * 数据访问记录
 *
 * @author Lingkai Shi
 * @email lingkai.shi@nnu.edu.cn
 * @date 2024-09-23 15:10:30
 */
@RestController
@RequestMapping("data/record")
public class RecordController extends AbstractController {
    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private ServiceService serviceService;

    @Autowired
    private RecordService recordService;

    @Resource
    private RecordConverter recordConverter;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("data:record:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = recordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("data:record:info")
    public R info(@PathVariable("id") Long id){
		RecordEntity record = recordService.getById(id);

        return R.ok().put("record", recordConverter.po2Vo(record, sysUserService, serviceService));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("data:record:save")
    public R save(@RequestBody RecordEntity record){
		recordService.save(record);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("data:record:update")
    public R update(@RequestBody RecordEntity record){
		recordService.updateById(record);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("data:record:delete")
    public R delete(@RequestBody Long[] ids){
		recordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
